home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / DCC_3DE.ZIP / FMM.ASM < prev    next >
Assembly Source File  |  1996-01-25  |  3KB  |  93 lines

  1. ;-----------------------------------------------------------------------------
  2. ; RealFlatMode initializing code by X-wizard
  3. ;-----------------------------------------------------------------------------
  4.  
  5. DOSSEG
  6. .MODEL huge
  7. .STACK 1024h
  8. .CODE
  9. .386p
  10.  
  11. assume ds:mygdt,cs:code16
  12. Mygdt SEGMENT PARA PUBLIC 'DATA' use16;also our datasegment
  13. GDT dw 4 dup(0)    ;defines a Global Descriptor Table,starting with a null entry
  14. GDT_code16=8
  15. dw 0ffffh,0,9a00h,0    ;descriptor for a 16-bit code segment
  16. GDT_code32=16
  17. dw 0ffffh,0,9a00h,0cfh ;descriptor for a 32-bit code segment
  18. GDT_data16=24
  19. dw 0ffffh,0,9200h,0    ;descriptor for a 64Kb data segment
  20. GDT_data32=32
  21. dw 0ffffh,0,9200h,8fh  ;descriptor for a 4Gb data segment
  22. ptr_GDT label fword
  23. dw 40-1                ;GDT size-1
  24. dd offset mygdt:gdt
  25. dw 0                   ;a pointer to your GDT
  26.  
  27. save_nmi db 0
  28. copyright db 'FMM By X-Wizard of DCC in 1994.',13,10
  29.           db 'All rights removed...',13,10,'$'
  30. Mygdt ENDS
  31.  
  32.  
  33. code16 SEGMENT PARA PUBLIC 'code' use16
  34. start:
  35. mov ax,mygdt
  36. mov ds,ax
  37. mov ax,code16   ;we initialise code16 descriptor
  38. movzx eax,ax
  39. shl eax,4             ;now eax=physical adress of code16 seg
  40. mov word ptr GDT[GDT_code16+2],ax
  41. ror eax,16
  42. mov byte ptr GDT[GDT_code16+4],al ;now code16 descriptor contains
  43.                                   ;starting of code16 segment
  44. mov ax,mygdt      ;dgroup is the name of a group from
  45.                   ;which you can access to the GDT
  46. movzx eax,ax
  47. shl eax,4
  48. add dword ptr ptr_GDT+2,eax
  49.                        ;now ptr_GDT+2 contains the physical
  50.                        ;adress of the GDT table in memory
  51. lgdt fword ptr ptr_GDT ;load this info in GDT register.
  52. cli
  53. in al,70h
  54. mov save_NMI,al
  55. mov al,80h
  56. out 70h,al
  57. mov eax,cr0
  58. or al,1
  59. mov cr0,eax
  60. db 0eah   ;this is a FAR JMP
  61. dw offset pmode   ;dd offset pmode if we are in a 32 bits code segment
  62. dw GDT_code16     ;we assume pmode is located in segment code16
  63.                   ;please notice that as we are now
  64.                   ;running in protected mode, we used
  65.                   ;code16 descriptor instead of just
  66.                   ;code16 segment (GDT_code16) instead
  67.                   ;of just (code16)
  68. pmode:
  69. mov ax,GDT_data32 ;load descriptor for 4Gb segment
  70. mov ds,ax         ;now ds limit is set to 4Gb
  71.                   ;the other segments are still limited
  72.                   ;to 64Kb but you can initialize them
  73.                   ;too if you need :
  74. mov es,ax
  75. mov fs,ax
  76. mov gs,ax         ;here all data segments are set to 4Gb
  77. mov eax,cr0
  78. and al,0feh
  79. mov cr0,eax
  80. db 0eah           ;this is a FAR JMP
  81. dw offset rmode   ;dd offset rmode
  82.                   ;if we are in a 32 bits code segment
  83. dw code16         ;we assume rmode is in segment code16
  84. rmode:
  85. sti
  86. mov al,save_NMI
  87. out 70h,al
  88. mov     ax,4c00h
  89. int     21h
  90. ends code16
  91.  
  92. end
  93.